package com.jeronimo.eko.core.beans;

import com.jeronimo.eko.core.beans.Encodable;

import edu.umd.cs.findbugs.annotations.SuppressWarnings;

@Encodable (messageClassId = 133,versionId=1)
@SuppressWarnings(value={"Bx","Dm","UwF","HE","USM","Nm","NP","RCN"})
public class BeanTest2 {

	String propString;
	
	BeanTest1 test1;
	
	BeanTest1[] test1array;

	BeanTest4 test4;
	
	char[] anotherFormOfString;
	
	BeanTestEnum testEnum;

	public void initTest1() {
		propString = "test1 !!!";
		test1 = new BeanTest1();
		test1.initTest1();
		BeanTest1 test2 = new BeanTest1();
		test2.initTest1();
		BeanTest1 test3 = new BeanTest1();
		test3.initTest2();
		BeanTest1 test4 = new BeanTest1();
		test4.initTest2();
		test1array = new BeanTest1[] {test2,test3,null,test4};
		this.test4 = new BeanTest4();
		this.test4.initTest1();
		BeanTestEnum e = new BeanTestEnum();
		e.initTest1();
		testEnum = e;
		anotherFormOfString = new String("char test are good !!").toCharArray();
	}
	
	public void initTest2() {
		propString = "test1 !!!";
		test1 = new BeanTest1();
		test1.initTest1();
		BeanTest1 test2 = new BeanTest1();
		test2.initTest1();
		BeanTest1 test3 = new BeanTest1();
		test3.initTest2();
		BeanTest1 test4 = new BeanTest1();
		test4.initTest2();
		test1array = new BeanTest1[] {test2,test3,null,test4};
		this.test4 = new BeanTest4();
		this.test4.initTest1();
		BeanTestEnum e = new BeanTestEnum();
		e.initTest2();
		testEnum = e;
		anotherFormOfString = null;
	}
	
	public String getPropString() {
		return propString;
	}

	@EncodableProperty
	public void setPropString(String propString) {
		this.propString = propString;
	}

	public BeanTest1 getTest1() {
		return test1;
	}
	
	@EncodableProperty	
	public void setTest1(BeanTest1 test1) {
		this.test1 = test1;
	}

	public BeanTest1[] getTest1array() {
		return test1array;
	}

	@EncodableProperty
	public void setTest1array(BeanTest1[] test1array) {
		this.test1array = test1array;
	}

	public BeanTest4 getTest4() {
		return test4;
	}

	@EncodableProperty
	public void setTest4(BeanTest4 test4) {
		this.test4 = test4;
	}

	public char[] getAnotherFormOfString() {
		return anotherFormOfString;
	}

	@EncodableProperty
	public void setAnotherFormOfString(char[] anotherFormOfString) {
		this.anotherFormOfString = anotherFormOfString;
	}

	public BeanTestEnum getTestEnum() {
		return testEnum;
	}

	@EncodableProperty
	public void setTestEnum(BeanTestEnum testEnum) {
		this.testEnum = testEnum;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof BeanTest2==false) {
			System.out.println("class type does not match");
			return false;
		}
		BeanTest2 c= (BeanTest2) obj;
		if (propString.equals(c.propString)==false) {
			System.out.println("propString does not match");
			return false;
		}
		if ((test1==null && c.test1==null)==false) {
			if (test1==null || test1.equals(c.test1)==false) {
				System.out.println("test1 beanTest1 does not match");
				return false;
			}
		}
		if ((test4==null && c.test4==null)==false) {
			if (test4==null || test4.equals(c.test4)==false) {
				System.out.println("test4 beanTest1 does not match");
				return false;
			}
		}
		if (test1array==null && c.test1array!=null) {
			System.out.println("test1 beanTest1 does not match nullability");
			return false;
		}
		try {
			for (int i=0;i<test1array.length;i++) {
				if ((test1array[i]==null && c.test1array[i]==null)==false) {
					if  (test1array[i]==null || test1array[i].equals(c.test1array[i])==false) {				
						System.out.println("test1array does not match at "+i);
						return false;
					}
				}
			}
		} catch (Throwable t) {
			t.printStackTrace();
			System.out.println("test1array does not match");
			return false;
		}
		
		if ((anotherFormOfString==null && c.anotherFormOfString==null)==false) {
			String s1 = null;
			if (anotherFormOfString!=null) {
				s1 = new String(anotherFormOfString);
			}
			String s2 = null;
			if (c.anotherFormOfString!=null) {
				s2 = new String(c.anotherFormOfString);
				if (s2.equals(s1)==false) {
					System.out.println("anotherformofstring does not match!!");
					return false;
				}
			}
			
		}
		
		if (testEnum!=null && c.testEnum!=null) {
			if (testEnum==null) return false;
			if (c.testEnum==null) return false;
			if (testEnum.equals(c.testEnum)==false) return false;
		}
		
		return true;
	}
	
	
	
}
